package com.xmy.aboutThread;

// ThreadLocal类的使用
public class Demo7 {

    static class ThreadA implements Runnable {

        private ThreadLocal<String> threadLocal;

        public ThreadA(ThreadLocal<String> threadLocal) {
            this.threadLocal = threadLocal;
        }

        @Override
        public void run() {
            threadLocal.set("threadA");

            System.out.println(threadLocal.get());
        }
    }

    static class ThreadB implements Runnable {

        private ThreadLocal<String> threadLocal;

        public ThreadB(ThreadLocal<String> threadLocal) {
            this.threadLocal = threadLocal;
        }

        @Override
        public void run() {
            threadLocal.set("threadB");

            System.out.println(threadLocal.get());
        }
    }
    public static void main(String[] args) {
        ThreadLocal threadLocal = new ThreadLocal();

        new Thread(new ThreadA(threadLocal)).start();

        new Thread(new ThreadB(threadLocal)).start();
    }
}
